var enableOCDC = (localStorage.getItem ("po_ama_enable_ocdc")=="true")?true:false;			// buttons for OC, BAL and DC
var enableTimebomb = (localStorage.getItem ("po_ama_enable_tb")=="true")?true:false;		// buttons for TB1 and TB2
var enableBoostsAgility = (localStorage.getItem ("po_ama_enable_ab")=="true")?true:false;		// agility boost button
var enableBoostsTaming = (localStorage.getItem ("po_ama_enable_tab")=="true")?true:false;		// taming boost button
var enableBoostsCloaking = (localStorage.getItem ("po_ama_enable_cb")=="true")?true:false;	// cloaking boost button
var useBtnForActivated = (localStorage.getItem ("po_ama_enable_show_active_button")=="true")?true:false;		// makes buttons for activated options
var showDisabledButtons = (localStorage.getItem ("po_ama_enable_show_hidden_buttons")=="true")?true:false;	// makes buttons for unavailable options
var enableBoosts = enableBoostsAgility || enableBoostsTaming || enableBoostsCloaking;

function AMAaddBtn(node, cmd, actName, val, label, config, clr) {

    var idx = config.search(val);

    // selected
    if(config[idx-1] == '!') {
        if(useBtnForActivated)
            {node.innerHTML = node.innerHTML + " <input type='submit' value='" + label + "' style='background-color:" + clr + "font-size:8pt;font-weight:bold;padding:1px;'>"}
        else
            {node.innerHTML = node.innerHTML + " <font style='color:" + clr + "font-size:8pt;font-weight:bold;padding:1px;'>" + label + "</font>"}
    }

    // disabled
    if(showDisabledButtons && config[idx-1] == '-') {
        node.innerHTML = node.innerHTML + " <input type='submit' value='" + label + "' disabled class='disabled' style='font-size:8pt;font-weight:bold;padding:1px;'>";
    }

    // clickable
    if(config[idx-1] == '|') {
        node.innerHTML = node.innerHTML + " <form action='overview_advanced_skills.php' Target='hidefrm' Method='post' style='display:inline'><input type='hidden' name='action' value='" + cmd + "'><input type='hidden' name='" + actName + "' value='" + val + "'><input type='submit' value='" + label + "' style='color:" + clr + "font-size:8pt;font-weight:bold;padding:1px;'></form>";
    }

}

function AMAaddButtonsTimebomb(aDiv) {

    // load timebombs, default is none available
    var timeBombs = localStorage.getItem('ama_timeBombs');
    if(!timeBombs) timeBombs = '';

    if(timeBombs != '') {
        AMAaddBtn(aDiv, 'deploy_timebomb', 'timebomb_type', 'type_1', 'Stun bomb', timeBombs, '#F0F000;');
        AMAaddBtn(aDiv, 'deploy_timebomb', 'timebomb_type', 'type_2', 'AP bomb', timeBombs, '#F0F000;');	
    }
}

function AMAaddButtonsOCDC(aDiv) {

    // load combat modes, default is balanced active and others disabled
    var combatModes = localStorage.getItem('ama_combatModes');
    if(!combatModes) combatModes = '|-offensive|!balanced|-defensive';

    // add combat mode buttons
    AMAaddBtn(aDiv, 'switch_combat_mode', 'combat_mode', 'offensive', 'OC', combatModes, '#FF0000;');
    AMAaddBtn(aDiv, 'switch_combat_mode', 'combat_mode', 'balanced', 'BAL', combatModes, '#A0A0A0;');
    AMAaddBtn(aDiv, 'switch_combat_mode', 'combat_mode', 'defensive', 'DC', combatModes, '#00FF00;');

}

function AMAaddButtonsBoosts(aDiv) {

    // load boost modes, default is no boosts available
    var boostModes = localStorage.getItem('ama_boostModes');
    if(!boostModes) boostModes = '';

    // these only get added if boosts available
    if(enableBoostsAgility) AMAaddBtn(aDiv, 'boost', 'boost', 'agility', 'AB', boostModes, '#00F0F0;');
    if(enableBoostsTaming) AMAaddBtn(aDiv, 'boost', 'boost', 'taming', 'TA', boostModes, '#00F0F0;');
    if(enableBoostsCloaking) AMAaddBtn(aDiv, 'boost', 'boost', 'cloaking', 'CL', boostModes, '#00F0F0;');

}

function AMAcheckActivationButtons() {

    // check if called from hidden frame then find buttons and update
    if(window.frameElement && window.frameElement.id == 'hidefrm') {
    
        var mainframe = window.parent.frames[2].document;
            
        if(enableOCDC) {
            var divActivations = mainframe.getElementById('activations');
            divActivations.innerHTML = '';
            AMAaddButtonsOCDC(divActivations)
        }

        if(enableTimebomb) {
            var divTimebombs = mainframe.getElementById('timebombs');
            divTimebombs.innerHTML = '';
            AMAaddButtonsTimebomb(divTimebombs)
        }

        if(enableBoosts) {
            var divBoosts = mainframe.getElementById('boosts');
            divBoosts.innerHTML = '';
            AMAaddButtonsBoosts(divBoosts)
        }

    }
}

function AMAgetCellStatus(btnCell, btnText)
{

    // mark active with !
    if(btnCell.tagName == 'B') {return '!' + btnText}

    // mark disabled with -
    // mark available with nothing
    if(btnCell.tagName == 'FORM') {
    if(btnCell.childNodes[2].getAttribute('class') == "disabled") {return '-' + btnText} else {return btnText}
    } else {
        if(btnCell.tagName == 'INPUT') {
            if(btnCell.getAttribute('class') == "disabled") {return '-' + btnText} else {return btnText}
        }
    }
}	

function AMAcheckHiddenFrame()
{
    var newFrame = window.top.document.getElementById('hidefrm');		
    if(newFrame == null) {
            newFrame = window.top.document.createElement('iframe');
            newFrame.id = 'hidefrm';
            newFrame.name = 'hidefrm';
            newFrame.width = 0;
            newFrame.height = 0;
            newFrame.src = '';
            newFrame.setAttribute("style", "display:none");
            window.top.document.body.appendChild(newFrame);
    }
}

//
// MAIN BODY
//

function AMAinstallMain() {

    AMAcheckHiddenFrame();
    var divStatusContent = document.getElementById('status_content');

    if(enableTimebomb && document.getElementById ("timebombs") == null) {
        var child = document.createElement("div");		
        child.id = 'timebombs';
        child.align = 'center';
        child.setAttribute("style", "top:3px; margin-left: 4px; margin-top: 4px; margin-bottom: 4px");
        AMAaddButtonsTimebomb(child);
        divStatusContent.appendChild(child);
    }

    // add combat modes and boosts into container div to keep on same line
    if((enableOCDC || enableBoosts) && document.getElementById ("ocdc") == null) {

        var container = document.createElement("div");
        container.id = "ocdc";
        container.setAttribute("style", "top:3px; margin-left: 6px; margin-right: 6px; margin-top: 4px; margin-bottom: 4px; line-height: 29px");
        container.align = 'center';

        if(enableOCDC) {
            var child = document.createElement("div");
            child.setAttribute("style", "display: inline; top:3px; margin-left: 4px; margin-top: 4px; margin-bottom: 4px");
            child.id = 'activations';
            AMAaddButtonsOCDC(child);
            container.appendChild(child);
        }

        if(enableBoosts) {
            var child = document.createElement("div");		
            child.setAttribute("style", "display: inline; top:3px; margin-left: 4px; margin-top: 4px; margin-bottom: 4px");
            child.id = 'boosts';
            AMAaddButtonsBoosts(child);
            container.appendChild(child);
        }

        divStatusContent.appendChild(container);

    }	
}


if (window.ajax == true) {
    window.addUserFunction(AMAinstallMain);
    AMAinstallMain();
} else {
    AMAinstallMain();
}
